const db = require('../db/index')


exports.getMajorCate = (req, res, next) => {
    const sql1 = 'select * from major_cate where isdelete = 0'
    db.query(sql1, (err, result) => {
        if(err) return res.show(err)
        if(result.length === 0) return res.show("查询不到专业类别！")

        req.majorCate = result
        // console.log(result)
        next()

    })
}



exports.getAllMajor = (req, res, next) => {
    console.log(req.query)
    const sql = 'select * from majors where isdelete = 0'
    db.query(sql, (err, result) => {
        if(err) return res.show(err)
        if(result.length === 0) return res.show("专业信息查询失败！")

        res.render('index', {majorCate: req.majorCate, majorData: result})

    })
}



// exports.getAllArticles = (req, res) => {
//     const sql = 'select * from articles where isdelete = 0'
//     db.query(sql, (err, result) =>{
//         if(err) return res.show(err)
//         // if(result.length === 0) return res.show("查询不到数据！")

//         res.render('content/html', { articleData: result })

//     })
// }


// // 根据专业类别查询所有文章
// exports.getArticleByCate = (req, res) => {
//     console.log(req.params.id)
//     const sql = 'select * from articles where majorId = ? and isdelete = 0'
//     db.query(sql, req.params.id, (err, result) => {
//         if(err) return res.show(err)
//         if(result.length === 0) return res.show("查询不到数据！")
//         console.log(result)

//         res.render('index', {majorCate: req.majorCate, majorData: req.majorData, articleData: result})
//     })
// }
